<?php
class check extends top
{
	//重定义构造函数
    function __construct(){  
        parent::__construct();
        //定义当前导航
        $this->nav_name = 'check';
        $this->page_title = '申请用户管理';
        $this->breadcrumb += array('1'=>array('name'=>'验证','url'=>spUrl('check')));

    }
	function index(){
		$member = spClass('m_member');

		$data = $this->spArgs();
		if( isset($data['member_id']) ){
			if( isset($data['check_agree']) ){
				$update_arr = array('state'=>1);
			}
			if( isset($data['check_disagree']) ){
				$update_arr = array('state'=>2);
			}
			$member->update('id='.$data['member_id'],$update_arr);
		}

		if(isset($data['state']) && in_array($data['state'],array(0,1,2)) ){
			$where = " state = ".$data['state'];
		}else{
			$where = "1";
		}

		$sort= 'add_time DESC';
		$fields = 'id,name,phone,email,unit,intro,add_time,state';
		$member_result = $member->spPager($this->spArgs('page', 1), 10)->findAll($where,$sort,$fields);
		$this->pager = $member->spPager()->getPager();
		$this->member_result = $member_result;
		$this->c = 'check';
		$this->a = 'index';		
		$this->data_return = $data;
		//var_dump($this->member_result);	
	}

	function edit(){
		$member = spClass('m_member');
		$data = $this->spArgs();

		if( isset($data['member_id']) ){
			$target_member = $member->find(array('id' => $data['member_id']) );
			$this->target_member_result = $target_member;
			$this->c = 'check';
			$this->a = 'edit';
			$this->data_return = $data;
		}
		if( isset($data['is_edit_submit']) && isset($data['change_do']) ){
			$change_arr = array(
				'name' => $data['change_name'],
				'phone' => $data['change_phone'],
				'unit' => $data['change_unit'],
				'email' => $data['change_email'],
				'intro' => $data['change_intro'],
				);
			$member->update('id='.$data['change_id'],$change_arr);
			
			$this->jump(spUrl('check','index'));
		}
	}

	function out(){
		$result = spClass('m_member')->findAll("state = 1","add_time DESC");

		header("Content-type:application/vnd.ms-excel");
		header("Content-Disposition:attachment;filename=members".date("Ymd",time()).".xls" );

		echo "姓名"."\t";
		echo "电话"."\t";
		echo "邮件"."\t";
		echo "单位"."\t";
		echo "研究领域"."\t";
		echo "申请时间"."\t";
		echo "\n";

		foreach($result as $val){
			echo $val['name']."\t";
			echo $val['phone']."\t";
			echo $val['email']."\t";
			echo $val['unit']."\t";
			echo $val['intro']."\t";
			echo $val['add_time']."\t";
			echo "\n";
		}
	}

}